Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Dijkstra version for digraph with edges weights #319

Closed
wants to merge 1 commit into from

Conversation

mariatsalakou
Copy link
Collaborator

No description provided.

@@ -1365,6 +1365,37 @@ InstallMethod(DigraphDijkstra, "for a digraph, and a vertex",
[IsDigraph, IsPosInt],
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail));

InstallMethod(DigraphDijkstraSTWeights, "for a digraph, a vertex, a vertex, and a list of weights",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using your new version DigraphDijkstraSTWeights as the code of DIGRAPHS_DijkstraST, with one change: the argument weights could be a function like:

weights := function(u, v)
  return list_of_weights[u][v];
end;

if a list of weights is given, and if no list of weights is given then we could do:

weights := function(u, v)
  return 1;
end;

u := Pop(queue);
u := u[2];
for v in OutNeighbours(digraph)[u] do
alt := dist[u] + weights[u][v];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would become weights(u, v) instead of weights[u][v]

@@ -1365,6 +1365,37 @@ InstallMethod(DigraphDijkstra, "for a digraph, and a vertex",
[IsDigraph, IsPosInt],
{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail))

would become

{digraph, source} -> DIGRAPHS_DijkstraST(digraph, source, fail, {u, v} -> 1))

InstallMethod(DigraphDijkstraSTWeights, "for a digraph, a vertex, a vertex, and a list of weights",
[IsDigraph, IsPosInt, IsPosInt, IsList],
function(digraph, source, target, weights)
local dist, prev, queue, u, v, alt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check that the weights have the same "shape" as OutNeighbours(digraph)

Copy link
Member

@james-d-mitchell james-d-mitchell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update as discussed.

@mariatsalakou mariatsalakou deleted the dijkstra3 branch July 29, 2020 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants